using System;
using System.Diagnostics;

namespace IBNet
{
   /// <summary>
   /// Historical Data Event Arguments
   /// </summary>
   [DebuggerDisplay("{recordNumber} / {recordTotal}, Date: {date.ToLongTimeString()}")]
   public class HistoricalDataEventArgs : EventArgs
   {
      private readonly int requestId;
      private readonly long openTimeSince1970;
      private readonly DateTime date;
      private readonly decimal open;
      private readonly decimal high;
      private readonly decimal low;
      private readonly decimal close;
      private readonly int volume;
      private readonly int trades;
      private readonly decimal wap;
      private readonly bool hasGaps;
      private readonly int recordNumber;
      private readonly int recordTotal;

      /// <summary>
      /// Creates a new HistoricalDataEventArgs.
      /// </summary>
      /// <param name="requestId">The request Id.</param>
      /// <param name="openTimeSince1970">The open time of the bar in seconds since 1970.</param>
      /// <param name="date">The open time of the bar as a DateTime.</param>
      /// <param name="open">The open price.</param>
      /// <param name="high">The high price.</param>
      /// <param name="low">The low price.</param>
      /// <param name="close">The close price.</param>
      /// <param name="volume">The volume.</param>
      /// <param name="trades">The trade count.</param>
      /// <param name="wap">The weighted average price.</param>
      /// <param name="hasGaps">Specifies whether there are gaps in the data.</param>
      /// <param name="recordNumber">The record number.</param>
      /// <param name="recordTotal">The total number of records.</param>
      public HistoricalDataEventArgs(int requestId, long openTimeSince1970, DateTime date,
         decimal open, decimal high, decimal low, decimal close, int volume, int trades,
         decimal wap, bool hasGaps, int recordNumber, int recordTotal)
      {
         this.requestId = requestId;
         this.hasGaps = hasGaps;
         this.wap = wap;
         this.trades = trades;
         this.volume = volume;
         this.close = close;
         this.low = low;
         this.high = high;
         this.open = open;
         this.openTimeSince1970 = openTimeSince1970;
         this.date = date;
         // + 1 to make 0-based recordNumber 1-based like 1-based recordTotal
         this.recordNumber = recordNumber + 1; 
         this.recordTotal = recordTotal;
      }

      /// <summary>
      /// Gets the request Id.
      /// </summary>
      public int RequestId
      {
         get { return requestId; }
      }

      /// <summary>
      /// Gets the open time of the bar in seconds since 1970.
      /// </summary>
      public long OpenTimeSince1970
      {
         get { return openTimeSince1970; }
      }

      /// <summary>
      /// Gets the open time of the bar as a DateTime.
      /// </summary>
      public DateTime Date
      {
         get { return date; }
      }

      /// <summary>
      /// Gets the open price.
      /// </summary>
      public decimal Open
      {
         get { return open; }
      }

      /// <summary>
      /// Gets the high price.
      /// </summary>
      public decimal High
      {
         get { return high; }
      }

      /// <summary>
      /// Gets the low price.
      /// </summary>
      public decimal Low
      {
         get { return low; }
      }

      /// <summary>
      /// Gets the close price.
      /// </summary>
      public decimal Close
      {
         get { return close; }
      }

      /// <summary>
      /// Gets the volume.
      /// </summary>
      public int Volume
      {
         get { return volume; }
      }

      /// <summary>
      /// Gets the trade count.
      /// </summary>
      public int Trades
      {
         get { return trades; }
      }

      /// <summary>
      /// Gets the weighted average price.
      /// </summary>
      public decimal Wap
      {
         get { return wap; }
      }

      /// <summary>
      /// Gets a value specifying whether or not there are gaps in the data.
      /// </summary>
      public bool HasGaps
      {
         get { return hasGaps; }
      }

      /// <summary>
      /// Gets the record number.
      /// </summary>
      public int RecordNumber
      {
         get { return recordNumber; }
      }

      /// <summary>
      /// Gets the record total.
      /// </summary>
      public int RecordTotal
      {
         get { return recordTotal; }
      }

   }
}
